# to replace ros in our project

class PubSub:
    def __init__(self):
        self.subscriptions = {}

    def create_publisher(self, topic):
        return Publisher(topic, self)

    def create_subscription(self, topic, callback):
        if topic in self.subscriptions:
            self.subscriptions[topic].append(callback)
        else:
            self.subscriptions[topic] = [callback]
        return self

    def publish(self, topic, msg):
        if topic in self.subscriptions:
            for sub in self.subscriptions[topic]:
                sub(msg)


class Publisher:
    def __init__(self, topic, manager):
        self.topic = topic
        self.manager = manager

    def publish(self, msg):
        self.manager.publish(self.topic, msg)


class Subscription:
    def __init__(self, topic, manager):
        self.topic = topic
        self.manager = manager